/* A vertex shader that assigns this vertex's
   texture coordinate attribute to a varying
   attribute that is interpolated for fragments.
*/

uniform vec3 lightSource, camera;
uniform vec4 ambientLight, diffuseLight, specularLight;

attribute vec2 vertex_texture_coordinate;

varying float intensity, dist;
varying vec2 fragment_texture_coordinate;
varying vec3 lightDir, normal, halfVector,eyeDir;
varying vec4 diffuse, ambientGlobal, ambient;
varying vec4 passcolor;

void main(void)
{
	/* we still need to assign a position and color for 
 	   the vertex.  By overriding the standard GL pipeline,
 	   GL no longer does this for us by default. 
	*/

	vec3 vVertex;
	vec3 aux;

	passcolor = gl_Color;
	fragment_texture_coordinate = vertex_texture_coordinate;

	normal = normalize(gl_NormalMatrix*gl_Normal);

	vVertex = vec3(gl_ModelViewMatrix*gl_Vertex);

	// Calculate the light vector and the distance to the light
	// translate the lightsource to camera coordinates
	aux = lightSource-camera;
	lightDir=normalize(aux - vVertex);
	dist=length(aux);

	// Calculate the vector to the viewer
	// We are in eye coordinate space, so the camera is at 0,0,0, therefore (0,0,0)-vVertex
	eyeDir=normalize(-vVertex);

	// Calculate the half vector
	aux=lightDir + eyeDir;
	halfVector=normalize(aux);
	
	diffuse = vec4(.8,.8,.8,1.0);
	ambient = vec4(.1,.1,.1,1.0);
//	diffuse = diffuseLight;
//	diffuse = gl_FrontMaterial.diffuse*diffuseLight;
//	diffuse = gl_FrontMaterial.diffuse*vec4(0.0,1.0,0.0,1.0);
//	ambient = gl_FrontMaterial.ambient*ambientLight;
//	ambient = gl_FrontMaterial.ambient*vec4(0.0,0.0,1.0,1.0);
//	ambientGlobal=gl_LightModel.ambient * gl_FrontMaterial.ambient;

	gl_Position=gl_ModelViewProjectionMatrix*gl_Vertex;
}
